#include <iostream>
#include <fstream>
using std::cout;
using std::endl;
using std::cerr;
using std::fstream;

void test(){
    fstream fs("1.txt");
    if(!fs.good()){
        cerr << "fs is not good" << endl;
        exit(-1);
    }
    //将游标移动到末尾
    fs.seekg(0, std::ios::end);
    //统计出文本的长度
    size_t index = fs.tellg();
    cout << index << endl;
    //再次将文件移动到最开始的位置
    fs.seekg(0, std::ios::beg);
    char * pstr = new char[index + 1]();
    //读取指定长度的数据到字符串中
    fs.read(pstr, index);
    cout << pstr << "---" << endl;
    delete [] pstr;
    pstr = nullptr;
}

int main()
{
    test();
    return 0;
}
